package org.mozhu.mboot.admin.system.account.entity;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.mozhu.mboot.core.data.entity.Activatable;
import org.mozhu.mboot.core.data.entity.AuditingEntity;
import org.mozhu.mboot.core.data.entity.LogicDeleteable;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.util.Date;

@Entity
@Table(name = "sys_user")
@Data
@EqualsAndHashCode(callSuper = true)
public class User extends AuditingEntity implements LogicDeleteable, Activatable {

    private static final long serialVersionUID = 239230219104716120L;

    // -- 必填项 -- //
    // 姓名
    protected String name;

    // 英文名
    protected String enName;

    // 登录名
    protected String loginName;

    // 不持久化到数据库，也不显示在Restful接口的属性.
    @Transient
    private String plainPassword;

    // 登录密码
    protected String password;

    // 性别
    @Enumerated(EnumType.STRING)
    protected Gender gender;

    // 用户邮箱
    protected String email;
    // 电话
    protected String phone;
    // 移动电话
    protected String mobile;
    // 传真
    protected String fax;
    // 通讯地址
    protected String address;
    // 邮编
    protected String postcode;

    // 上传头像
    protected String avatar;

    /**
     * 逻辑删除flag
     */
    private Boolean deleted = Boolean.FALSE;

    /**
     * 激活(TRUE)，冻结(FALSE)
     */
    private Boolean activated = Boolean.TRUE;

    public boolean isAvailable() {
        return !Boolean.TRUE.equals(this.deleted) && !isBlocked();
    }

    public boolean isBlocked() {
        return !Boolean.TRUE.equals(getActivated());
    }

}
